Back to course home
0% completed
Vote For New Content
Amazon Hard Problems
Constrained Subsequence Sum (hard)
Solution: Constrained Subsequence Sum
Number of Valid Subarrays (hard)
Solution: Number of Valid Subarrays
Count Vowels Permutation (hard)
Solution: Count Vowels Permutation
Concatenated Words (hard)
Solution: Concatenated Words
Minimum Replacements to Sort the Array (hard)
Solution: Minimum Replacements to Sort the Array
Count All Valid Pickup and Delivery Options (hard)
Solution: Count All Valid Pickup and Delivery Options
Length of the Longest Valid Substring (hard)
Solution: Length of the Longest Valid Substring
Count Array Pairs Divisible by K (hard)
Solution: Count Array Pairs Divisible by K
Word Ladder (hard)
Solution: Word Ladder
Path with Maximum Sum (hard)
Solution: Path with Maximum Sum
Largest Submatrix With Rearrangements (medium)
Problem Statement
You are given a binary matrix matrix of size m x n. You are allowed to shuffle the columns of the matrix in any order.
Return the area of the largest submatrix, whose all elements are 1 after shuffling the columns of the matrix.
Examples
Example 1:
- Input:
[[1,0,1],
[1,1,1],
[1,0,1]]
- Expected Output:
6
- Justification: By swapping the 2nd and 3rd columns, we can form a 2x2 rectangle of 1s. It forms the largest rectangle of 1s with an area of 6.
Example 2:
- Input:
[[0,1],
[1,1]]
- Expected Output:
2
- Justification: The columns can be rearranged (although in this case, it's not necessary) to form the largest rectangle of 1s that is 1x2 or 2x1. The area is 2.
Example 3:
- Input:
[[1,1,0,0],
[1,0,1,1],
[1,1,1,1],
[0,1,1,0]]
- Expected Output:
6
- Justification: By swapping the 2nd and 4th column, we can form a 3x2 rectangle of 1s. It forms the largest rectangle of 1s with an area of 6.
Try it yourself
Try solving this question here:
Java
. . . .
Solution: Maximum Length of Subarray With Positive Product
Solution: Largest Submatrix With Rearrangements
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself